/**
 * A base class for objects that need to fire events.
 * @constructor
 */
lib.event.EventTarget = function() {
	this.listenerMap_ = {};
};

/**
 * Add a listener for the event of the specified type to the event target.
 * @param {String} type The type of the event.
 * @param {Function} listener The listener function.
 */
lib.event.EventTarget.prototype.listen = function(type, listener) {
	if (!this.listenerMap_[type]) {
		this.listenerMap_[type] = [];
	}
	
	this.listenerMap_[type].push(listener);
};

/**
 * Remove a listener for the event of the specified type to the event target.
 * @param {String} type The type of the event.
 * @param {Function} listener The listener function.
 */
lib.event.EventTarget.prototype.unlisten = function(type, listener) {
	if (this.listenerMap_[type]) {
		this.listenerMap_[type].remove(listener);
	}
};

/**
 * Trigger the event of the specified type of the event target.
 * @param {String} type The type of the event.
 * @private
 */
lib.event.EventTarget.prototype.trigger_ = function(type) {
	var listeners = this.listenerMap_[type];
	if (listeners) {
		arguments[0] = {target: this, type: type};
		for (var i=0, len=listeners.length; i<len; ++i) {
			listeners[i].apply(null, arguments); 
		}
	}
};
